from PIL import Image
im = Image.open("sample.jpg")
im
im.format
im.size
im.mode
new_size = (128, 128)
im.thumbnail(new_size) #直接更改 im
im
im.size
im.save("sample_thumbnail.jpg", "JPEG")
im = Image.open("sample.jpg")
new_im = im.crop((100,100,400,400)) #回傳新照片
new_im
im.resize((128, 128))
im = Image.open("sample.jpg")
im = im.resize((800, 600)) ##圖片小一點
for i in range(800):
for j in range(600):
r, g, b = im.getpixel((i, j))
value = int(0.299*r + 0.587*g + 0.114*b)
r = value
g = value
b = value
im.putpixel((i,j), (r, g, b))
im
im = Image.open("sample.jpg")
im = im.resize((800, 600)) ##圖片小一點
new_im = Image.new("RGB", (800,600))
for i in range(800):
for j in range(600):
r, g, b = im.getpixel((i,j))
r = 255-r
g = 255-g
b = 255-b
new_im.putpixel((i,j), (r, g, b))
new_im
new_im = Image.new("RGB", (800,600))
for i in range(800):
for j in range(600):
pass
#add your code here
new_im
import random
Id, R, G, B = [],[],[],[]
for i in range(256):
Id.append(i)
R.append(0)
G.append(0)
B.append(0)
for i in range(256):
R[i] = i
for i in range(1000000):
x = random.uniform(0, 255) #平均分佈
G[int(x)] += 1
y = random.normalvariate(128, 50) #常態分佈
if 0 <= y <= 255:
B[int(y)] += 1
%matplotlib notebook
from matplotlib import pyplot
pyplot.figure(1)
pyplot.subplot(311)
pyplot.fill_between(Id, R, color='red')
pyplot.subplot(312)
pyplot.fill_between(Id, G, color='green')
pyplot.subplot(313)
pyplot.fill_between(Id, B, color='blue')